package com.yayo.mangement.service.impl;

import com.google.common.collect.Maps;
import com.yayo.mangement.conf.DbConfig;
import com.yayo.mangement.dao.TableDao;
import com.yayo.mangement.model.Table;
import com.yayo.mangement.paging.PageInfo;
import com.yayo.mangement.paging.Paging;
import com.yayo.mangement.service.TableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class TableServiceImpl implements TableService {

    @Autowired
    private TableDao tableDao;

    @Override
    public Paging<Table> paging(Integer pageNo, Integer pageSize,String tableName) {
        PageInfo pageInfo = new PageInfo(pageNo,pageSize);
        Map<String, Object> params = Maps.newHashMap();
        params.put("limit", pageInfo.getLimit());
        params.put("offset", pageInfo.getOffset());
        params.put("databaseName",DbConfig.getDbName());
        params.put("tableName",tableName);
        return tableDao.paging(params);
    }

    @Override
    public Table findByTableName(String tableName) {
        Table table = new Table();
        table.setTableName(tableName);
        return tableDao.findByTableName(table);
    }
}
